package com.lagou.task18;

public class ThreadDaemonTest extends Thread{
    @Override
    public void run() {
        for (int i = 1; i <= 50 ; i++) {
            //当子线程不是守护线程时，虽然主线程先结束，但子线程仍然会继续执行,直到结束
            //当子线程是守护线程时，主线程结束，子线程也会结束
            System.out.println("子线程 = " + i);
        }
    }

    public static void main(String[] args) {
        ThreadDaemonTest td1 = new ThreadDaemonTest();
        //必须在子线程启动之前设置为守护线程
        td1.setDaemon(true);
        td1.start();

        for (int i = 1; i <= 20 ; i++) {
            System.out.println("主线成 = " + i);
        }
    }
}
